/*
* @Author: Marte
* @Date:   2019-02-20 12:36:19
* @Last Modified by:   Marte
* @Last Modified time: 2019-10-13 02:18:51
*/

package main

import (
    "fmt"
    "log"
    "os"
    "strings"
    "gin-filestore/config"
    "gin-filestore/mq"
    "gin-filestore/db/mysql"
    "gin-filestore/cache/redis"
    "gin-filestore/handler"
    "gin-filestore/route"
)

func main() {
    // 日志配置
    fmt.Println("日志配置...")
    path := "logs"
    mode := os.ModePerm
    if _, err := os.Stat(path); os.IsNotExist(err) {
        os.Mkdir(path, mode)
    }
    file, _ := os.Create(strings.Join([]string{path, "log.txt"}, "/"))
    defer file.Close()
    logger := log.New(file, "", log.Ldate|log.Ltime|log.Lshortfile)
    logger.SetFlags(2)

    // 数据库初始化
    redis.InitRedis()
    mysql.InitMysql()
    mq.InitMq()

    // 目录初始化
    handler.InitTemp()

    fmt.Println("初始化路由...")
    //gin framework
    router := route.Router()
    router.Run(config.DefaultConfig.UploadServiceHost)

}
